package ${package.ServiceImpl};


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import net.bigdata.cloud.framework.common.api.HttpCodeEnum;
import net.bigdata.cloud.framework.common.api.Resp;
import net.bigdata.cloud.framework.common.dto.BasePageDto;
import net.bigdata.cloud.framework.common.dto.IdBaseDto;
import ${superServiceImplClassPackage};
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author ： ${author}
 * @date ：Created in ${date}
 * @description：${table.comment!} 服务实现类
 * @modified By：
 * @version: 1.0
 */
@Service
@Slf4j
public class ${table.serviceImplName} extends ServiceImpl<${table.mapperName}, ${entity}> implements ${table.serviceName} {



    @Override
    public Resp<Boolean> addByPo(${entity} dto) {
        try {
            ${entity} po=new ${entity}();
            BeanUtils.copyProperties(dto, po);
            if (!super.save(po)) {
                return Resp.failed(HttpCodeEnum.PARAMETER_ERROR);
            }
            return Resp.success(Boolean.TRUE);
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_ERROR);
        }
    }

    @Override
    public Resp<Boolean> updateByPo(${entity} dto) {
        try {
            ${entity} byId = super.getById(dto.getId());
            if (null == byId) {
                return Resp.failed(HttpCodeEnum.NOT_FOUND);
            }
            ${entity} po=new ${entity}();
            BeanUtils.copyProperties(dto, po);
            if (!super.updateById(po)) {
                return Resp.failed(HttpCodeEnum.PARAMETER_ERROR);
            }
            return Resp.success(Boolean.TRUE);
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_ERROR);
        }
    }


    @Override
    public Resp<${entity}> detail(IdBaseDto dto) {
        try {
            ${entity} byId = super.getById(dto.getId());
            if (null == byId) {
                return Resp.failed(HttpCodeEnum.NOT_FOUND);
            }
            return Resp.success(byId);
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_ERROR);
        }
    }

    @Override
    public Resp<Boolean> removeByPo(IdBaseDto dto) {
        try {
            ${entity} byId = super.getById(dto.getId());
            if (null == byId) {
                return Resp.failed(HttpCodeEnum.NOT_FOUND);
            }
            if (!super.removeById(byId.getId())) {
                return Resp.failed(HttpCodeEnum.PARAMETER_ERROR);
            }
            return Resp.success(Boolean.TRUE);
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_ERROR);
        }
    }


    /**
    * ${table.comment!}分页列表
    * @dto dto 根据需要进行传值
    * @return
    */
    @Override
    public Resp<IPage<${entity}>> getPage(BasePageDto dto) {
        try {
            Page<${entity}> page = new Page<>(dto.getCurrent(), dto.getPageSize());
            QueryWrapper<${entity}> wrapper = new QueryWrapper();
            return Resp.success(baseMapper.selectPage(page, wrapper));
        } catch (Exception e) {
            log.error("服务调用异常：", e);
            return Resp.failed(HttpCodeEnum.INVOKE_ERROR);
        }
    }


}
